package org.hot100_5.leetcode3;

import java.util.HashSet;

public class Solution {
    public static void main(String[] args) {
        String str = "abcabcbb";
        lengthOfLongestSubstring(str);
    }
    public static int lengthOfLongestSubstring(String s) {

        int n = s.length();

        int slow = 0, fast = 0;

        HashSet<Character> hashSet = new HashSet<>();
        int maxLength = 0;
        while (fast < n) {

            if (slow > 0) {
                hashSet.remove(s.charAt(slow - 1));
            }
            while (fast < n && !hashSet.contains(s.charAt(fast))) {
                hashSet.add(s.charAt(fast));
                fast++;
            }

            maxLength = Math.max(maxLength, fast - slow);

            slow++;
        }

        return maxLength;
    }
}
